{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "2f25735f-12ff-4e53-b377-8436cc2e2474",
   "metadata": {},
   "source": [
    "https://leetcode.com/problems/letter-combinations-of-a-phone-number\n",
    "\n",
    "\n",
    "Runtime: 32 ms, faster than 61.61% of Python3 online submissions for Letter Combinations of a Phone Number.\n",
    "Memory Usage: 14.2 MB, less than 84.69% of Python3 online submissions for Letter Combinations of a Phone Number.\n",
    "\n",
    "\n",
    "\n",
    "```python\n",
    "import math\n",
    "\n",
    "class Solution:\n",
    "    def letterCombinations(self, digits: str) -> List[str]:\n",
    "        #7:54\n",
    "        if (digits == \"\"):\n",
    "            return []\n",
    "\n",
    "        num_to_abc_map = {\n",
    "            \"2\": \"abc\",\n",
    "            \"3\": \"def\",\n",
    "            \"4\": \"ghi\",\n",
    "            \"5\": \"jkl\",\n",
    "            \"6\": \"mno\",\n",
    "            \"7\": \"pqrs\",\n",
    "            \"8\": \"tuv\",\n",
    "            \"9\": \"wxyz\",\n",
    "        }\n",
    "        for key in num_to_abc_map.keys():\n",
    "            num_to_abc_map[key] = list(num_to_abc_map[key])\n",
    "            \n",
    "        possible_set_list = [num_to_abc_map[digit] for digit in digits]\n",
    "        length = math.prod([len(i) for i in possible_set_list])\n",
    "        \n",
    "        def loop(index, result):\n",
    "            if index == 0 and len(result) == 0:\n",
    "                return loop(index+1, possible_set_list[index])\n",
    "            elif len(result) == length:\n",
    "                return result\n",
    "            \n",
    "            new_list = []\n",
    "            for num1 in result:\n",
    "                for num2 in possible_set_list[index]:\n",
    "                    new_list.append(num1+num2)\n",
    "\n",
    "            return loop(index+1, new_list)\n",
    "            \n",
    "        return loop(0, [])\n",
    "        #8:44\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3be52f75-4a94-4fff-abd8-7cda0e4d5056",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
